<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-model-item label="标题">
              <a-input placeholder="请输入标题" v-model="queryParam.title"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-model-item label="是否播报">
              <a-select placeholder="请选择是否播报" ref="select" v-model="queryParam.isBroad" @change="handleChange">
                <a-select-option :value="1">已播报</a-select-option>
                <a-select-option :value="0">未播报</a-select-option>
              </a-select>
            </a-form-model-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->
    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
    </div>
    <!-- table区域-begin -->
    <div>
      <a-table
        :columns="columns"
        :data-source="dataSource"
        :rowKey="(item) => item.id"
        :pagination="ipagination"
        :loading="loading"
        class="j-table-force-nowrap"
        @change="handleTableChange"
      >
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px; font-style: italic">无图片</span>
          <span v-for="(itme, index) in text.split(',')" :key="index">
            <img
              @click="showPopovers(itme)"
              :src="getImgViews(itme)"
              alt=""
              style="max-width: 80px; height: 40px; font-size: 12px; font-style: italic; margin-right: 8px"
            />
          </span>
        </template>
        <template slot="description" slot-scope="text">
          <span :title="text">{{ !text ? '' : text.length > 10 ? text.substr(0, 15) + '...' : text }}</span>
        </template>
        <template slot="isBroad" slot-scope="text">
           <a-tag color="green" v-if="text === 1">已播报</a-tag>
           <a-tag color="orange" v-else>未播报</a-tag>
        </template>
        <span slot="operation" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>
          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a @click="handleDetails(record)">详情</a>
              </a-menu-item>
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
              <a-menu-item>
                <a @click="set(record)">{{ record.isBroad === 1 ? '取消播报' : '设为播报' }}</a>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>
      </a-table>
    </div>
    <culturalHistory-modal ref="modalForm" @ok="modalFormOk" @close="close"></culturalHistory-modal>
  </a-card>
</template>

<script>
import { getAction, getFileAccessHttpUrl } from '@/api/manage'
import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import culturalHistoryModal from './modal/culturalHistoryModal.vue'
import JDictSelectTag from '@/components/dict/JDictSelectTag.vue'
import YearSelect from '@/components/jeecg/YearDateSelect.vue'
import NP from 'number-precision'
import { delTqppCulturalHistory, dpChangeBroadOn, dpChangeBroadOff } from '@/api/dashboardPaltform'
export default {
  name: 'culturalTourList',
  mixins: [JeecgListMixin, mixinDevice],
  components: {
    YearSelect,
    JDictSelectTag,
    culturalHistoryModal,
  },
  data() {
    return {
      showPopover: false,
      urls: '',
      imagelist: [],
      createTime: [],
      positionList: [],
      description: '枇杷文化历史',
      // 表头
      columns: [
        { title: '标题', dataIndex: 'title', key: 'title' },
        {
          title: '内容',
          dataIndex: 'description',
          key: 'description',
          scopedSlots: { customRender: 'description' },
          //   customRender: function (text) {
          //     return !text ? '' : text.length > 10 ? text.substr(0, 15)+'...' : text
          //   },
        },
        {
          title: '图片',
          width: 200,
          dataIndex: 'certificateImgUrls',
          key: 'certificateImgUrls',
          scopedSlots: { customRender: 'imgSlot' },
        },
        {
          title: '是否播报',
          width: 200,
          dataIndex: 'isBroad',
          key: 'isBroad',
          scopedSlots: { customRender: 'isBroad' },
        },
        { title: '操作', key: 'operation', scopedSlots: { customRender: 'operation' } },
      ],
      dataSource: [],
      innerData: [],
      isorter: {},
      url: {
        list: '/loquat/tqppCulturalHistory/list',
        delete: '/loquat/tqppCulturalHistory/delete',
      },
      dictOptions: {},
    }
  },
  watch: {
    dataSource: {
      handler(val) {
        if (val) {
          // val.map(item=>{
          // this.innerData.push(...item.plantNumberList)
          // })
        }
      },
      immediate: true,
      deep: true,
    },
  },
  mounted() {},
  computed: {},
  methods: {
    // showPopovers(res) {
    //   this.showPopover = true
    //   this.urls = res
    // },
    set(data) {
      if (data.isBroad === 1) {
        this.$confirm({
          title: '是否确定取消该条数据的播报',
          onOk: () => {
            this.dpChangeBroadOff(data.id)
          },
          onCancel() {
            console.log('Cancel')
          },
          centered: true,
        })
      } else {
        this.$confirm({
          title: '是否确定将该条数据设为播报？',
          onOk: () => {
            this.dpChangeBroadOn(data.id)
          },
          onCancel() {
            console.log('Cancel')
          },
          centered: true,
        })
      }
    },
    async dpChangeBroadOn(val) {
      let res = await dpChangeBroadOn({ id: val })
      if (res.success) {
        this.$message.success(res.result)
        this.searchQuery()
      } else {
        this.$message.error(res.message)
      }
    },
    async dpChangeBroadOff(val) {
      let res = await dpChangeBroadOff({ id: val })
      if (res.success) {
        this.$message.success(res.result)
        this.searchQuery()
      } else {
        this.$message.error(res.message)
      }
    },
    getImgViews(data) {
      return getFileAccessHttpUrl(data)
    },
    close() {
      this.searchQuery()
    },
    clickdelete(id) {
      this.$confirm({
        title: '您确定要删除该条记录吗？',
        onOk: () => {
          this.delTqppCulturalHistory(id)
        },
        onCancel() {
          console.log('Cancel')
        },
        centered: true,
      })
    },
    async delTqppCulturalHistory(val) {
      let res = await delTqppCulturalHistory({ id: val })
      if (res.success) {
        this.$message.success(res.message)
        this.searchQuery()
      } else {
        this.$message.error(res.message)
      }
    },
    getNum(val) {
      return NP.round(NP.times(val, 100), 2) + '%'
    },
    initDictConfig() {},
  },
}
</script>
<style scoped lang="less">
@import '~@assets/less/common.less';
.table-page-search-wrapper {
  /deep/ .ant-calendar-range-picker-input {
    font-size: 12px;
  }
}
</style>